﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;

namespace WPGame.BaseObject
{
    //7ung
    abstract class MyObject
    {
        private ID m_ID;
        private eGStatus m_Status;

        private Graphics.Sprite m_Sprite;

        private GTimer m_Timer;

        public MyObject(int col, Rectangle baserect, Vector2? position = null)
        {
            Sprite = new Graphics.Sprite(col, baserect, position);
            Timer = new GTimer();
            Status = eGStatus.NORMAL;
        }

        public MyObject(eGSprite _spirte, ID _id, Vector2 position )
        {
            Sprite = ResourceManager.GSpriteFactory.getInstance().getSprite(_spirte);
            Sprite.Position = position;
            ID = _id;
            Timer = new GTimer();
            Status = eGStatus.NORMAL;
        }

        virtual public void Draw(SpriteBatch spritebatch)
        {
            this.setFrame();
            this.m_Sprite.Render(spritebatch);
        }

        virtual protected void setFrame()
        {
            Sprite.Frame = new Rectangle(
                Sprite.BaseRect.X + Sprite.CurFrame * Sprite.BaseRect.Width,
                Sprite.BaseRect.Y,
                Sprite.BaseRect.Width,
                Sprite.BaseRect.Height);
        }

        virtual public bool isCollision(MyObject obj)
        {
            return (this.Sprite.Bound.Intersects(obj.Sprite.Bound));
        }

        abstract public void Update(GameTime gametime);

        abstract public void Update(TouchCollection _touchcollection);

        #region Property

        public ID ID
        {
            get { return m_ID; }
            set { m_ID = value; }
        }

        public Graphics.Sprite Sprite
        {
            get { return m_Sprite; }
            set { m_Sprite = value; }
        }

        public GTimer Timer
        {
            get { return m_Timer; }
            private set { m_Timer = value; }
        }

        public eGStatus Status
        {
            get { return m_Status; }
            set
            {
                m_Status = value;
            }
        }

        #endregion
    }
}
